import {
  exportUrl,
  getPropertieIdList,
  getCharacteristicIdList,
  getYesOrNotList,
} from "@/api/materials/mesProdCharacteristic";
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true,
    disabled: (data) => {
      return !data.length > 0;
    },
  },
  {
    name: $i18n.t("mesProdCharacteristic.enable"),
    type: "success",
    icon: "el-icon-unlock",
    handleName: "publish", //点击时返回的标识
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
  },
  {
    name: $i18n.t("mesProdCharacteristic.deactivate"),
    type: "warning",
    icon: "el-icon-lock",
    handleName: "deactivate", //点击时返回的标识
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      return data.length != 1;
    },
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    prodCode: {
      type: "input",
      label: $i18n.t("mesProdCharacteristic.prodCode"),
    },
    prodName: {
      type: "input",
      label: $i18n.t("mesProdCharacteristic.prodName"),
    },
    // propertieId: {
    //   type: "select",
    //   label: "物料属性",
    //   type: "select",
    //   prop: {
    //     value: "value",
    //     text: "description",
    //   },
    //   options: async (data) => {
    //     const list = await getPropertieIdList();
    //     return list.data.result;
    //   },
    // },
    characteristicId: {
      type: "select",
      label: $i18n.t("mesProdCharacteristic.characteristicId"),
      prop: {
        value: "id",
        text: "characteristicName",
      },
      options: async (data) => {
        const list = await getCharacteristicIdList({ activeFlag: "1" });
        return list.data.result;
      },
    },
    isReport: {
      type: "select",
      label: $i18n.t("mesProdCharacteristic.isReport"),
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getYesOrNotList();
        return list.data.result;
      },
    },
    activeFlag: {
      type: "select",
      label: $i18n.t("mesProdCharacteristic.activeFlag"),
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getYesOrNotList();
        return list.data.result;
      },
    },
  },
};
export const formDescDialogMinxin = {
  data() {
    const self = this;
    return {
      // 新增/删除表单配置
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        formDesc: {
          prodCode: {
            type: "input",
            label: $i18n.t("mesProdCharacteristic.prodCode"),
            layout: 12,
            disabled: (d) => !!d.id,
            required: true,
          },
          prodName: {
            type: "input",
            label: $i18n.t("mesProdCharacteristic.prodName"),
            layout: 12,
            disabled: true,
            required: true,
          },
          propertieId: {
            type: "select",
            label: $i18n.t("mesProdCharacteristic.propertyId"),
            layout: 12,
            required: true,
            prop: {
              value: "id",
              text: "propName",
            },

            options: async () => {
              const list = await getPropertieIdList({ activeFlag: "1" });
              const data = list.data.result;
              self.propertiesList = data;
              return data;
            },
            on: {
              change: (val) => {
                self.handleChange(val);
              },
            },
          },
          characteristicId: {
            type: "select",
            label: $i18n.t("mesProdCharacteristic.characteristicId"),
            layout: 12,
            required: true,
            attrs: {
              filterable: true,
            },
            optionsLinkageFields: ["propertieId"],
            prop: {
              value: "id",
              text: "characteristicName",
            },
            options: async (data) => {},
          },

          isReport: {
            type: "select",
            label: $i18n.t("mesProdCharacteristic.isReport"),
            layout: 12,
            required: true,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getYesOrNotList();
              return list.data.result;
            },
          },
          activeFlag: {
            type: "switch",
            label: $i18n.t("mesProdCharacteristic.activeFlag"),
            layout: 12,
            required: false,
            valueFormatter(labels) {
              return labels == "1" ? "1" : "0";
            },
            displayFormatter(labels) {
              return labels == "1" ? true : false;
            },
          },
          remark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 24,
            required: false,
          },
        },
      },
    };
  },
};
